package com.wlyuan.open.scanner.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wlyuan.open.scanner.application.annotation.DataScope;
import com.wlyuan.open.scanner.dao.entity.DriverDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author yuanjie
 * @since 2022-09-23
 */
public interface DriverMapper extends BaseMapper<DriverDO> {

    String QUERY_SQL = "SELECT Driver_ID, opt_status, SUBSTRING(Driver_Name,0,80) as driverName, Driver_Gender, Driver_Photo, Driver_Birthday, Driver_Phone, Driver_LicensedDate, Driver_LicenseType, Driver_SN, Driver_PersonalSN, Driver_CompanyID, Driver_Creator, Driver_InsertTime, Driver_Updater, Driver_UpdateTime, Driver_Invalid, Driver_Comments, Driver_Heat, Driver_UserId " +
            "FROM TMS_MDriver ";

    String WHERE = "WHERE Driver_CompanyID > 0 ";

    /**
     * 查询司机列表
     *
     * @return
     */
    @Select(QUERY_SQL + WHERE)
    @DataScope(column = "Driver_CompanyID")
    List<DriverDO> list();

    /**
     * 根据id获取
     *
     * @param id
     * @return
     */
    @Select(QUERY_SQL + "WHERE Driver_ID = #{id}")
    DriverDO getById(Long id);

    @Select(QUERY_SQL + "WHERE Driver_CompanyID = #{tenantId}")
    List<DriverDO> getByTenantId(Long tenantId);

    @Select("SELECT Driver_ID FROM TMS_MDriver WHERE Driver_InsertTime >= #{startTime} and Driver_InsertTime <= #{endTime}")
    List<Long> getByTime(@Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT Driver_ID FROM TMS_MDriver WHERE Driver_CompanyID = #{tenantId} and Driver_InsertTime >= #{startTime} and Driver_InsertTime <= #{endTime}")
    List<Long> getByTenantIdTime(@Param("tenantId") Long tenantId, @Param("startTime") String startTime, @Param("endTime") String endTime);
}
